package com.sskj.gocoin.p.activity;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.gocoin.MyAppLication;
import com.sskj.gocoin.common.Constants;
import com.sskj.gocoin.m.HttpConfig;
import com.sskj.gocoin.m.bean.HttpData;
import com.sskj.gocoin.m.bean.ImgHighBean;
import com.sskj.gocoin.m.http.JsonCallBack;
import com.sskj.gocoin.p.base.BasePresenter;
import com.sskj.gocoin.utils.SPUtils;
import com.sskj.gocoin.utils.ToastUtil;
import com.sskj.gocoin.v.activity.VerifyGuideActivity;

import java.io.File;
import java.util.HashMap;


public class VerifyGuidePresenter extends BasePresenter<VerifyGuideActivity> {

    //    public void submitVerify(HashMap<String, Object> params) {
//        String mobile = (String) SPUtils.get(MyAppLication.getApplication(), Constants.SP_MOBILE, "");
//        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.HIGH_VERIFY)
//                .isMultipart(false)
//                .params("cardimg3", (File) params.get("photo_a"), (String) params.get("photoAName"))  // 手持
//                .params("cardimg1", (File) params.get("photo_b"), (String) params.get("photoBName"))
//                .params("cardimg2", (File) params.get("photo_c"), (String) params.get("photoCName"))  //身份证背面
//                .execute(new JsonCallBack<HttpData>(this) {
//                    @Override
//                    public void _onSuccess(Response<HttpData> response) {
//                        HttpData body = response.body();
//                        if (body.status == 200) {
//                            mView.onSubmitVerifyResponseSuccess();
//                            SPUtils.put(MyAppLication.getApplication(), Constants.SP_REALNAME_STATUS_HIGH, 2);
//                        } else {
////                            mView.onSubmitVerifyResponseSuccess();
//                            ToastUtil.showShort(body.msg);
//                        }
//                    }
//                });
//    }
    public void submitVerify(File file, int position) {
        OkGo.<HttpData<ImgHighBean>>post(HttpConfig.BASE_URL + HttpConfig.HIGH_VERIFY_IMG)
                .isMultipart(false)
                .params("file_pic", file)
                .execute(new JsonCallBack<HttpData<ImgHighBean>>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData<ImgHighBean>> response) {
                        HttpData body = response.body();
                        if (body.status == 200) {
                            ToastUtil.showShort(body.msg);
                            ImgHighBean hignBean = (ImgHighBean) body.getData();
                            mView.putList(hignBean.getUrl());
                        } else {
                            mView.uploadFail(position);
//                            mView.onSubmitVerifyResponseSuccess();
                            ToastUtil.showShort(body.msg);
                        }
                    }
                });
    }

    public void submitVerifyEnd(HashMap<String, Object> params) {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.HIGH_VERIFY)
                .params("cardimg3", (String) params.get("photoAName"))  // 手持
                .params("cardimg1", (String) params.get("photoBName"))
                .params("cardimg2", (String) params.get("photoCName"))  //身份证背面
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData> response) {
                        HttpData body = response.body();
                        if (body.status == 200) {
                            mView.onSubmitVerifyResponseSuccess();
                            SPUtils.put(MyAppLication.getApplication(), Constants.SP_REALNAME_STATUS_HIGH, 2);
                        } else {
//                            mView.onSubmitVerifyResponseSuccess();
                            ToastUtil.showShort(body.msg);
                        }
                    }
                });
    }
}
